package org.grayrabbit.cms.util;

import java.util.Collection;
import java.util.Collections;

import org.grayrabbit.cms.ComponentManager;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.PicoContainer;


public class CmsUtils {

	public static Object loadComponent(Class<?> componentClass) {
		return loadComponent(componentClass, Collections.EMPTY_LIST);
	}

	public static Object loadComponent(Class<?> componentClass,Collection<?> extraParamaters) {
		PicoContainer applicationContainer = ComponentManager.getInstance().getContainer();
		DefaultPicoContainer tempContainer = new DefaultPicoContainer(applicationContainer);
		for (Object parameter : extraParamaters) {
			tempContainer.addComponent(parameter);
		}
		tempContainer.addComponent(componentClass);
		return tempContainer.getComponent(componentClass);
	}

}
